﻿''' <summary>
''' Summary of NavFx Application
''' </summary>
Partial Public Class App
	Inherits Global.NavFx.Application


#Region "Constructors"

	''' <summary>
	''' Default constructor
	''' </summary>
	Public Sub New()
		MyBase.New()
		InitializeComponent()
	End Sub

#End Region

#Region "Event handlers"

	''' <summary>
	''' Load the main page when the application starts
	''' </summary>
	''' <param name="sender"></param>
	''' <param name="e"></param>
	Private Sub Application_Startup(ByVal sender As Object, ByVal e As StartupEventArgs) Handles Me.Startup

		'Load the main empty page that acts
		'as a shell for all content
		Me.RootVisual = New Shell()

		'set up the navigator with the appropriate
		'transition handler, important to do Me
		'before loading any NavFx pages
		Dim appNavigator As Navigator = MyBase.GetNavigator()
		appNavigator.Transitor = New SimpleTransitor(Application.Current)

		Dim homePage As Home = New Home()
		appNavigator.RegisterPage(CType(homePage, IPage))
		appNavigator.GoToPage("Home")

	End Sub

	''' <summary>
	''' Handles cleanup when the application exits
	''' </summary>
	Private Sub Application_Exit(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Exit


	End Sub

	''' <summary>
	''' Global handler for unhandled exceptions
	''' </summary>
	Private Sub Application_UnhandledException(ByVal sender As Object, ByVal e As ApplicationUnhandledExceptionEventArgs) Handles Me.UnhandledException

		' If the app is running outside of the debugger then report the exception Imports
		' the browser's exception mechanism. On IE Me will display it a yellow alert 
		' icon in the status bar and Firefox will display a script error.
		If Not System.Diagnostics.Debugger.IsAttached Then


			' NOTE: This will allow the application to continue running after an exception has been thrown
			' but not handled. 
			' For production applications Me error handling should be replaced with something that will 
			' report the error to the website and stop the application.
			e.Handled = True

			Try

				Dim errorMsg As String = e.ExceptionObject.Message + e.ExceptionObject.StackTrace
				errorMsg = errorMsg.Replace(""""c, "\"c).Replace("\r\n", "\n")

				System.Windows.Browser.HtmlPage.Window.Eval("throw New Error(""Unhandled Error in NavFx Application " + errorMsg + """);")
			Catch

			End Try
		End If
	End Sub

#End Region
End Class
